/*****************************************************************************/
/** \file mc_singleshut.h
**
** 
**
** History:
** 
*****************************************************************************/
#ifndef  __MC_SINGLESHUT_H__
#define  __MC_SINGLESHUT_H__


/*****************************************************************************/
/* Include files */
/*****************************************************************************/
#include   "mc_pmsm.h"

/*****************************************************************************/
/* Global pre-processor symbols/macros ('#define') */
/*****************************************************************************/
#ifndef	 	PWMBASEFERQUE
#define  	PWMBASEFERQUE					64000000
#endif
#ifndef	 	PWMFREQUE
#define	 	PWMFREQUE						16000
#endif
#ifndef	 	PWMPERIOD
#define	 	PWMPERIOD						(PWMBASEFERQUE/PWMFREQUE)/2				
#endif

#define		CALFULLDUTY						32768											//Q15
#define		PWMPERIOD_QUAD					PWMPERIOD/4
#define		PWMTIMEBASE						PWMBASEFERQUE/1000000
#define		ADCCONVERTIME					PWMTIMEBASE*3									//adc convert time is 3us
#define		DCBUSSETTIME					PWMTIMEBASE*1.2									//dc bus settime is 1us	
#define		DEVEDEADTIME					PWMTIMEBASE*1.4									//power device deadtime is 0.7*2us

#define		TSAM_MIN						(64*4)
#define		TSAM_MINDOU						TSAM_MIN*2
#define		TSAM_HALF						TSAM_MIN/2
#define		TSAM_QUAD						TSAM_HALF/2
#define		TSAM_EITH						TSAM_QUAD/2
#define		TSAM_DELAY						0

/*****************************************************************************/
/* Global type definitions ('typedef') */
/*****************************************************************************/
typedef struct
{
	u8  Sector;
	s32 Ia;
	s32 Ib;
	s32 Ic;
}Rephasecurr;

typedef struct
{
	u8  Sector;
	u8  Flag_CH1;
	u8  Flag_CH2;
	u16 T1;
	u16 T2;
	u16 ShiftWidth;
}Valpwmclock;

typedef	struct
{
	s32	Ta_Base;
	s32	Tb_Base;
	s32	Tc_Base;
	s32	Ta_Up;
	s32	Tb_Up;
	s32	Tc_Up;
	s32	Ta_Dn;
	s32	Tb_Dn;
	s32	Tc_Dn;	
	u32	Ca_Dn;
	u32	Cb_Dn;	
	u32	Cc_Dn;	
}Pwmreisterval;

/*****************************************************************************/
/* Global variable declarations ('extern', definition in C source) */
/*****************************************************************************/
extern Rephasecurr						Single_Current;
extern Pwmreisterval					Single_DutyVal;

/*****************************************************************************/
/* Global function prototypes ('extern', definition in C source) */
/*****************************************************************************/
extern void  							MC_PWM_TG(void);
extern void  							MC_GET_CURR(void);
extern void  							MC_SINGLESHUNT(SVM_Components *p);


#endif	 /* __MC_SINGLESHUT_H__ */


